package com.neutech.neusys.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.neutech.dto.Paging;
import com.neutech.neusys.service.SysService;
import com.neutech.po.Sgory;
import com.neutech.po.Sys;
import com.neutech.po.User;
import com.neutech.vo.PagingVo;

@RestController
@RequestMapping(value="/his/sys")
public class SysController {
	@Autowired
	private SysService sysService;
	 
//	删除
	@RequestMapping("/getDeleteSys")
	public Sys getDeleteUser(int id) throws Exception{
		Sys sys = sysService.deleteSys(id);
		return sys;
	}
//	修改
	@RequestMapping(value="/getUpdateSys",method=RequestMethod.POST)
	public Sys getUpdateUser(Sys sys) throws Exception{
		sys = sysService.updateSys(sys);
		return sys;
	}
//	增加
	@RequestMapping(value="/getInsertSys",method=RequestMethod.POST)
	public Sys getInsertUser(Sys sys) throws Exception{
		sys = sysService.insertSys(sys);
		return sys;
	}
//	查询
	@RequestMapping("/getSelectSys")
	public Sys getUser(Integer id) throws Exception{
		Sys sys = sysService.findSys(id);
		return sys;
	}
	/**
	*添加用户
	*@param:user 用户信息
	*@return:添加成功还是失败,"success"--成功,"error"--失败
	* @throws Exception 
	*/
	@RequestMapping(value ="/addSgory",method=RequestMethod.POST)
	public String addNewSgory (@RequestBody Sgory sgory) throws Exception{
		int result = sysService.addSgory(sgory);
		if(result == 1){
			return "success";
		}else{
			return "error";
		}
		
	}
	
	
	/**
	*查询用户
	*@param:user 用户信息
	*@return:添加成功还是失败,"success"--成功,"error"--失败
	* @throws Exception 
	*/
	@RequestMapping("/selectSettle")
	public List<Sgory> toNewSettle() throws Exception{
		return  sysService.getSettleAll();	
	}
	
	// 获取结算列表-关键字过滤数据
	@RequestMapping(value = "/getSgorySelectList", method = RequestMethod.POST)
	public List<Sgory> getSgorySelectList(@RequestBody Map<String, String> keyStringMap) {

		String keyString = keyStringMap.get("keyString");
		System.out.println(keyString);
		List<Sgory> result = sysService.getSgorySelectList(keyString);
		return result;
	}

	// 获取结算列表-分页显示
	@RequestMapping(value = "/getSgory", method = RequestMethod.POST)
	public List<Sgory> getSgory(@RequestBody PagingVo vo) {
		Paging paging = new Paging();
		paging.setPages(vo.getPages());
		paging.setRowsPerPage(vo.getRowsPerPage());
		paging.setBeginRows(vo.getRowsPerPage() * (vo.getPages() - 1));
		paging.setKeyString("%" + vo.getKeyString() + "%");
		List<Sgory> result = sysService.getSgory(paging);
		return result;
	}

	// 获取分页显示总行数
	@RequestMapping(value = "/getSgoryCount", method = RequestMethod.POST)
	public int getSgoryCount(@RequestBody PagingVo vo) {		
		Paging paging = new Paging();
		paging.setKeyString("%" + vo.getKeyString() + "%");
		System.out.println("KeyString" + paging.getKeyString());
		int result = sysService.getSgoryCount(paging.getKeyString());
		System.out.println("result" + result);
		return result;
	}
	
	/**
	 * 修改表单
	 */
	@RequestMapping(value="/updateNewSgory",method = RequestMethod.POST)
	public Sgory updateNewSgory (@RequestBody Sgory sgory) throws Exception{
		sgory = sysService.updateSgory(sgory);
			return sgory;
		
	}
	
	/**
	 * 删除表单
	 * 
	 */
	@RequestMapping(value = "/deleteSgory",method = RequestMethod.POST)
	public Sgory deleteSgory (@RequestBody Sgory sgory) throws Exception{
		sgory = sysService.deleteSgory(sgory);
		return sgory;
	}
}
